package main

func maxAreaOfIsland(grid [][]int) int {
	max := 0
	for i, row := range grid {
		for j, v := range row {
			if v == 1 {
				area := 0
				bfs(grid, i, j, &area)
				if area > max {
					max = area
				}
			}
		}
	}
	return max
}

func bfs(grid [][]int, i, j int, area *int) {
	if i < 0 || j < 0 || i >= len(grid) || j >= len(grid[0]) {
		return
	}
	if grid[i][j] == 0 {
		return
	}
	grid[i][j] = 0
	*area++
	bfs(grid, i-1, j, area)
	bfs(grid, i+1, j, area)
	bfs(grid, i, j-1, area)
	bfs(grid, i, j+1, area)
}

func main() {

}
